<?php
/*
 * Created on 2012-2-29
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
include("../../nncms_manager_inc.php");
include $nncms_config_path. "nn_cms_manager/controls/nncms_controls_check_login.php";
//导入语言包
if (isset($_SESSION["language_dir"])){
    $language_dir=$_SESSION["language_dir"];
}
include $nncms_config_path. "nn_cms_manager/languages/". $language_dir. "/language.php";
include $nncms_config_path. "nn_cms_manager/languages/". $language_dir. "/language_media.php";
include_once dirname(dirname(dirname(dirname(__FILE__)))) . '/nn_logic/nl_common.func.php';


//获取权限检查类
include $nncms_db_path. "nns_pri/nns_db_pri_class.php";
$checkpri=new nns_db_pri_class();

$pri_bool=false;
$pri_bool=$checkpri->nns_db_pri_check($_SESSION["nns_role_pris"],"137102");
$checkpri=null;
if (!$pri_bool) Header("Location: ../nncms_content_wrong.php");
include ($nncms_config_path. "nn_cms_config/nn_cms_global.php");

$dc = nl_get_dc(array (
		"db_policy" => NL_DB_WRITE,
		"cache_policy" => NP_KV_CACHE_TYPE_MEMCACHE
));
$result_cp = nl_cp::query_all($dc);
if($result_cp['ret'] != 0)
{
	echo '<script>alert("'.$result_cp['reason'].'");history.go(-1);</script>';die;
}
$result_cp = isset($result_cp['data_info']) ? $result_cp['data_info'] : null;
$arr_cp_info = array();
if(is_array($result_cp) && !empty($result_cp))
{
	foreach ($result_cp as $val)
	{
		if(!isset($val['nns_type']) || $val['nns_type']==1)
		{
			continue;
		}
		$arr_cp_info[$val['nns_id']] = $val['nns_name'];
	}
}

$arr_type = array(
		'video_import' => '主媒资',
		'index_import' => '分集',
		'media_import' => '片源',
);
$arr_queue_name = array(
		'core_import' => '中心同步队列',
		'c2_import' => 'C2队列',
);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="../../css/allstyle.css" rel="stylesheet" type="text/css" />
    <link href="../../css/rightframestyle.css" rel="stylesheet" type="text/css" />
    <link href="../../css/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
    <link href="../../css/uploadify.css" rel="stylesheet" type="text/css" />
    <script language="javascript" src="../../js/jquery-1.4.3.min.js"></script>
    <script language="javascript" src="../../js/table.js.php"></script>
    <script language="javascript" src="../../js/radiolist.js"></script>
    <script language="javascript" src="../../js/checkinput.js.php"></script>
    <!--<script language="javascript" src="../../js/cms_datepicker.js"></script>-->
    <script language="javascript" src="../../js/checkinput.js.php"></script>
    <script language="javascript" src="../../js/swfobject.js"></script>
    <script language="javascript" src="../../js/muti_upload/jquery.uploadify.min.js"></script>

    <script language="javascript">
        var stauts_log='';   
        $(document).ready(function(){   
            <?php $timestamp = time();?>
            $('#stock_data_file').uploadify({            	
                'formData'     : {
                    'timestamp' : '<?php echo $timestamp;?>',
                    'token'     : '<?php echo md5('unique_salt' . $timestamp);?>',
                    'session_id':'<?php echo $_SESSION['nns_mgr_id'];?>',
                    'language_dir':'<?php echo $_SESSION['language_dir']?>',
                    'nns_org_id':'<?php echo $_SESSION['nns_org_id']?>',
                    'nns_org_type':'<?php echo $_SESSION['nns_manager_type']?>',
                    'nns_role_id':'<?php echo $_SESSION['nns_role_id']?>',
                },
                'fileTypeExts':'*.csv',
                'buttonText':'选择导入文件',
                'scriptAccess':'always',
                'fileDesc':'请选择csv文件',
                'swf'      : 'uploadify.swf',
                'successTimeout':30,
                'auto'         : true,
                'uploader' : 'nncms_content_stock_import_by_csv_control.php',
                'onQueueComplete':function(data){
                    $('#stauts_log').html(stauts_log);
                    window.parent.resetFrameHeight();
                },
                'overrideEvents' : [ 'onDialogClose', 'onSelectError' ],
                'onSelectError':uploadify_onSelectError,
                'onUploadSuccess':function(file,data,response){
                    var stauts_str='';
                    var json_data=eval("("+data+")");
                    if (json_data.ret == '0'){
                        stauts_str = file.name+' ----- '+'<span>'+json_data.info+'</span> ----- <span><a href="nncms_content_stock_import_control.php?nns_action=download&file_path='+json_data.file+'">下载CSV文件</a></span>';
                    }else{
                        stauts_str = file.name+' ----- '+'<span>'+json_data.info+'</span> ----- <span><a href="nncms_content_stock_import_control.php?nns_action=download&file_path='+json_data.file+'">下载CSV文件</a></span>';
                    }
                    stauts_str+='<br>';
                    stauts_log+=stauts_str;
                    window.parent.resetFrameHeight();
                },
                'onUploadStart':function(file){
    				$('#stock_data_file').uploadify(
    	    				'settings',
    						'formData',
    						{
    							'nns_cp_id'     : $("#nns_cp_id").val(),
    							'nns_type'      : $("#nns_type").val(),
    							'nns_queue_name': $("#nns_queue_name").val(),
    						}
    				);
            	},
            });
        });

        var uploadify_onSelectError = function(file, errorCode, errorMsg){
            var msgText = "文件上传失败\n";
            switch (errorCode) {
                case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
                    msgText = "文件格式不正确，仅限csv文件";
                    break;
                default:
                    msgText = errorMsg;
            }
            alert(msgText);
        }

        function js_download()
        {
            location.href="nncms_content_stock_import_by_csv_control.php?nns_action=download";
        }

    </script>
</head>

<body>

<div class="content" style="background:#fff;">
    <div class="content_position">媒资导入</div>
        <div class="content_table">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                <tr>
                	<td width="120"><span style="color:#FF0000; font-size:16px; font-weight:bold;">*</span>CP名称:</td>
            		<td>
            			<select style="width:300px;"  name='nns_cp_id' id='nns_cp_id'>
            				<option value=''>--请选择上游来源--</option>
            				<?php if(is_array($arr_cp_info) && !empty($arr_cp_info)){foreach ($arr_cp_info as $cp_key=>$cp_val){?>
            					<option value="<?php echo $cp_key;?>"><?php echo $cp_key.' / ' . $cp_val;?></option>
            				<?php }}?>
            			</select>
            		</td>
                </tr>
                <tr>
                	<td width="120"><span style="color:#FF0000; font-size:16px; font-weight:bold;">*</span>导入媒资类型:</td>
            		<td>
            			<select style="width:300px;"  name='nns_type' id='nns_type'>
            				<option value=''>--请选择媒资类型--</option>
            				<?php foreach ($arr_type as $key=>$val){?>
            					<option value="<?php echo $key;?>"><?php echo $val;?></option>
            				<?php }?>
            			</select>
            		</td>
                </tr>
                <tr>
                	<td width="120">队列名:</td>
            		<td>
            			<select style="width:300px;"  name='nns_queue_name' id='nns_queue_name'>
            				<option value=''>--请选择队列--</option>
            				<?php foreach ($arr_queue_name as $q_key=>$q_val){?>
            					<option value="<?php echo $q_key;?>"><?php echo $q_val;?></option>
            				<?php }?>
            			</select>&nbsp;&nbsp;&nbsp;&nbsp;<font color="red">未选择队列时将不会生成注入队列</font>
            		</td>
                </tr>
                <tr>
                    <td width="120">CSV存量数据文件</td>
                    <td>
                        <div style="padding-top:10px;"><input name="stock_data_file" id="stock_data_file" type="file" size="60%" multiple="true"  /></div><font color="red">文件格式为CSV文件。<a href="nncms_content_stock_import_by_csv_control.php?web_action=download_csv">下载CSV示例</a></font>
                    </td>
                </tr>
                <tr>
                    <td width="120">上传状态</td>
                    <td ><div id="stauts_log"  style="min-height:40px;"></div></td>
                </tr>
                </tbody>
            </table>
        </div>
    <div class="controlbtns">
        <div class="controlbtn back"><a href="javascript:$('#stock_data_file').uploadify('stop');">取消上传</a></div>
        <div style="clear:both;"></div>
    </div>
</div>
</body>
</html>
